package View;

import java.io.Serializable;

import javax.swing.JButton;
import javax.swing.JFrame;

import java.awt.Font;
import java.awt.List;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JLabel;

import Controller.ReportsController;
import Entity.CommentReport;
import Entity.CustomerReport;
import java.awt.Component;
import javax.swing.SwingConstants;

/** this class provide the GUI window for add new customer's report*/
public class CustomerReportView extends JFrame implements Serializable {
	private static final long serialVersionUID = 42L;
	
	/**required  fields and buttons */
	JLabel lblCustomerid;
	JLabel lblTotalPurchased;
	JLabel lblEffecMarketingCampaign;
	JButton btnBack;
	List list;
	ReportsView reportsView;
	ReportsController reportsController= ( ReportsController	) this.reportsController;
	private JLabel lblEffectiveness;

	/**
	 * Default and only constructor
	 * @param Cst
	 */
	public CustomerReportView(CustomerReport Cst) {
		getContentPane().setFont(new Font("Tahoma", Font.BOLD, 12));
		getContentPane().setLayout(null);
		setTitle("Customer Report");
		getContentPane().setLayout(null);
		this.setSize(539,455);
		this.setLocationRelativeTo(null); 

		list = new List();
		list.setMultipleMode(true);
		list.setFont(new Font("Dialog", Font.BOLD, 21));
		list.setBounds(35, 92, 464, 267);
		getContentPane().add(list);

		lblCustomerid = new JLabel("CustomerID");
		lblCustomerid.setFont(new Font("Dialog", Font.BOLD, 12));
		lblCustomerid.setBounds(96, 53, 94, 37);
		getContentPane().add(lblCustomerid);

		lblTotalPurchased = new JLabel("Total purchased");
		lblTotalPurchased.setToolTipText("Total Products Purchesed");
		lblTotalPurchased.setFont(new Font("Dialog", Font.BOLD, 12));
		lblTotalPurchased.setBounds(222, 53, 122, 37);
		getContentPane().add(lblTotalPurchased);

		lblEffecMarketingCampaign = new JLabel("Marketing campaign");
		lblEffecMarketingCampaign.setAlignmentX(Component.CENTER_ALIGNMENT);
		lblEffecMarketingCampaign.setToolTipText("Shows percentage of purchases");
		lblEffecMarketingCampaign.setName("");
		lblEffecMarketingCampaign.setHorizontalAlignment(SwingConstants.TRAILING);
		lblEffecMarketingCampaign.setFont(new Font("Dialog", Font.BOLD, 12));
		lblEffecMarketingCampaign.setBounds(354, 34, 128, 29);
		getContentPane().add(lblEffecMarketingCampaign);
		
		lblEffectiveness = new JLabel("effectiveness");
		lblEffectiveness.setToolTipText("percentage of purchases");
		lblEffectiveness.setName("");
		lblEffectiveness.setHorizontalAlignment(SwingConstants.TRAILING);
		lblEffectiveness.setFont(new Font("Dialog", Font.BOLD, 12));
		lblEffectiveness.setAlignmentX(0.5f);
		lblEffectiveness.setBounds(393, 57, 77, 29);
		getContentPane().add(lblEffectiveness);

		btnBack = new JButton("Back");
		btnBack.setFont(new Font("Tahoma", Font.BOLD, 15));
		btnBack.setBounds(239, 363, 89, 29);
		getContentPane().add(btnBack);
		btnBack.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent e) 
			{
				if (e.getSource()==btnBack)
				{
				hideWindow();
				reportsController.showWindow();
				}
			}
		});
		
		for(int i=0;i<Cst.getCustomersArraySize();i++)
		{
			list.add(i+1 +":              "+Cst.getTotalCustomers()[i] +"                      " 
			+ Cst.getTotalBought()[i] +"                      "
			+ Cst.getTotalPercent()[i]);
		}
		this.setVisible(true);
	}

	/**show and hide window functions */
	public void showWindow()
	{
		setVisible(true);
	}
	public void hideWindow()
	{
		setVisible(false);
	}
}

